<textarea id = "printwnd" width=120 height=120></textarea>
<div id = "testbox">ss</div>

<script language="jscript">
	
	var html_tags = [
		"a",
		"abbr",
		"acronym",
		"address",
		"applet",
		"area",
		"article",
		"aside",
		"audio",
		"b",
		"base",
		"basefont",
		"bdi",
		"bdo",
		"big",
		"blockquote",
		"br",
		"button",
		"canvas",
		"caption",
		"center",
		"cite",
		"code",
		"col",
		"colgroup",
		"datalist",
		"dd",
		"del",
		"details",
		"dfn",
		"diaprint",
		"dir",
		"div",
		"dl",
		"dt",
		"em",
		"embed",
		"fieldset",
		"figcaption",
		"figure",
		"font",
		"footer",
		"form",
		"h1",
		"h2",
		"h3",
		"h4",
		"h5",
		"h6",
		"hr",
		"i",
		"iframe",
		"img",
		"input",
		"ins",
		"kbd",
		"keygen",
		"label",
		"legend",
		"li",
		"main",
		"map",
		"mark",
		"menu",
		"menuitem",
		"meter",
		"object",
		"ol",
		"optgroup",
		"option",
		"output",
		"p",
		"param",
		"pre",
		"progress",
		"q",
		"rp",
		"rt",
		"ruby",
		"s",
		"samp",
		"section",
		"select",
		"small",
		"source",
		"span",
		"strike",
		"strong",
		"style",
		"sub",
		"summary",
		"sup",
		"table",
		"tbody",
		"td",
		"textarea",
		"tfoot",
		"th",
		"thead",
		"time",
		"title",
		"tr",
		"track",
		"tt",
		"u",
		"ul",
		"var",
		"video",
		"wbr"
	];
	
	var num_of_html_tags = html_tags.length;
	
	var	all_alloced_elements = [];
	var property_blacklist = {};
	
	var printwnd = document.getElementById( "printwnd" );
	var testbox = document.getElementById( "testbox" );
	
	function print( msg )
	{
		printwnd.value += msg + "\r\n";
	}
	
	function R(mod) {
		return Math.floor(Math.random() * mod);
	}
	
	function xx()
	{
		testbox.innerHTML = "";
	}
	
	function tigger_event(object)
	{
		for (name in object) 
		{
			try 
			{
				var n = ( name.indexOf("on") );
				if( n == 0 )
				{
					object[name]();
				}
			} 
			catch (e) 
			{ 
				print('...received exception (' + e + ')');
			}
		}
	}
	
	function change_properties(object) 
	{
		for (name in object) 
		{
			try 
			{ 
				var i = R(all_alloced_elements.length);
				var n = ( name.indexOf("on") );
				if( n == 0 )
					object[name] = xx;
				else if( typeof(object[name]) == 'function' )
				{
					var res1 = object[name]( "asda" );
					var res2 = object[name]( 12312 );
					var res3 = object[name]( object );
					var res4 = object[name]( all_alloced_elements[i] );
				}
				else if( typeof(object[name]) == 'object' )
				{
					change_properties( object[name] );
				}
				else
				{
					object[name] = all_alloced_elements[i];
				}
			} 
			catch (e) 
			{ 
				print('...received exception (' + e + ')');
			}
		}
	}
	// step 1, construct a complex DOM Tree
	function construct_dom_tree( root, depth, width, MAX_DEPTH )
	{
		if( depth > MAX_DEPTH ) return ;
		for( var w = 0; w < width; ++ w )
		{
			var tag = html_tags[ R(num_of_html_tags) ];
			//print( tag );
			var element = document.createElement( tag );
			root.appendChild( element );
			all_alloced_elements.push( element );
			construct_dom_tree( element, depth + 1, width, MAX_DEPTH );
		}
	}
	function construct_dom( root, width, depth )
	{
		construct_dom_tree( root, 0, width, depth );
	}

	function destroy_dom_tree( root )
	{
		while( root.firstChild != null )
		{
			destroy_dom_tree( root.firstChild );
			root.removeChild( root.firstChild );
		}
	}
	
	function main()
	{
		// construct a dom tree
		construct_dom( testbox, 3, 3 );

		for( var i = 0; i < all_alloced_elements.length; ++ i )
		{
			change_properties( all_alloced_elements[i] );
		}
		
		destroy_dom_tree( testbox );
	
		CollectGarbage();
		
		/*
		for( var i = 0; i < all_alloced_elements.length; ++ i )
		{
			try {
				all_alloced_elements[i].on_propertychange = on_propertychange;
			} 
			catch( e )
			{
				change_properties( e );
			}
		}
		*/

		// tigger event;
		for( var i = 0; i < all_alloced_elements.length; ++ i )
		{
			var j = all_alloced_elements.length - i - 1;
			tigger_event( all_alloced_elements[j] );
		}
		
		all_alloced_elements = [];

		CollectGarbage();
		
		setTimeout( "main();", 10 );
	}

	function construct_on_time()
	{
		construct_dom( testbox, 3,3 );
		for( var i = 0; i < all_alloced_elements.length; ++ i )
		{
			change_properties( all_alloced_elements[i] );
		}
		CollectGarbage();
		setTimeout( "construct_on_time();", 10 );
	}
	
	function free_on_time()
	{
		destroy_dom_tree( testbox );
		for( var i = 0; i < all_alloced_elements.length; ++ i )
		{
			change_properties( all_alloced_elements[i] );
		}
		all_alloced_elements = [];
		CollectGarbage();
		setTimeout( "free_on_time();", 10 );
	}

	alert( "start" );
	
	setTimeout("main()",10);
	//setTimeout("construct_on_time()",10);
	//setTimeout("free_on_time()",10);
	
</script>